<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./js/vue.js"></script>
    <title>更新时的问题</title>
    <style>
        [v-cloak]{
            display:none;
        }
    </style>
</head>
<body>
    <div id="root" :x="n">  
        <!-- 
        -->
        <h2>当前的n值是: {{n}}</h2>
        <button @click="add">n+1</button>
        <button @click="bye">销毁vm对象</button>
    </div>
</body>
<script>
   
    var vm = new Vue({
        el: '#root',
        /* template:`
            <div>
                <h2>当前的n值是: {{n}}</h2>
                <button @click="add">n+1</button>
            </div>`, */
        data: {
            n:1
        },
        // 生命周期钩子1
        beforeCreate() {
            console.log('beforeCreate');
            console.log(this);
            // debugger;
        },
        created() {
            console.log('created');
            // console.log(this);
            // debugger;
        },
        beforeMount() {
            console.log('beforeMount');
            // console.log(this);
            // document.querySelector("h2").innerHTML = "哈哈";
            // debugger;
        },
        mounted() {
            console.log('mounted');
            // console.log(this);
            // document.querySelector("h2").innerHTML = "哈哈";
            // debugger;
        },
        beforeUpdate() {
            console.log('beforeUpdate');
            // console.log(this.n);
            // debugger;
        },
        updated() {
            console.log('updated');
            console.log(this.n);
            // debugger;
        },
        beforeDestroy() {
            console.log('beforeDestroy');   
        },
        destroyed() {
            console.log('destroyed');
        },
        compute:{
            n(){
                console.log('n变了');
            }
        },
        methods: {
            add() {
                console.log('n+1');
                this.n++;
            },
            bye() {
                console.log('销毁vm对象');
                vm.$destroy();
            }
        }
    })
   
</script>
</html>